/**
 * 
 */
package org.gov.vis.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.TimeZone;

import org.apache.log4j.Logger;
import org.gov.vis.master.dto.CodeDesc;

/**
 * @author Muralidhar Yaragalla
 *
 *This is an utility class.
 */
public class Util {
	private static ResourceBundle resources;	
	private static Logger log = Logger.getLogger(Util.class);
	
	//constants for the Database Configurations
	private static final String DATABASE_HOST_URL = "localhost";
	private static final String DATABASE_NAME = "vis";
	private static final String DATABASE_USER_NAME = "root";
	private static final String DATABASE_PASSWORD = "kensium";
	
	static {
        try {
            resources = ResourceBundle.getBundle("org.gov.vis.util.resources.vis" );
        } catch (MissingResourceException mre) {
            System.err.println("resources/vis.properties not found"+mre);            
            System.exit(1);
        }
    }

	/**
	 * This method instances the driver and gives the database connection
	 * @return
	 */
	public static Connection getConnection(){
		Connection conn=null;
		try{
			Class.forName("com.mysql.jdbc.Driver").newInstance();			
			conn =DriverManager.getConnection("jdbc:mysql://" + DATABASE_HOST_URL + "/" + DATABASE_NAME + "?" +
                    "user=" + DATABASE_USER_NAME + "&password=" + DATABASE_PASSWORD);
		}catch(Exception e){
			log.debug(e.getMessage(), e);
		}
		
		return conn;
	}
	
	
	
	/**
	 * This method returns the resource bundle object.
	 * @return ResourceBundle
	 */
	public static ResourceBundle getResources() {
		return resources;
	}
	
	/**
	 * It returns the default time zone id.
	 * @return timezone Id.
	 */
	public static String getDefaultTZId(){
		TimeZone defaultTZ=TimeZone.getDefault();
		String id=defaultTZ.getID();
		return id;
	}
	
	/**
	 * Method called to get all the Job Types as CodeDesc
	 * @return
	 */
	public static List<CodeDesc> getAllJobTypes(){
		List<CodeDesc> jobTypeList = new ArrayList<CodeDesc>(3);
		CodeDesc codeDesc = null;
		for(long i = DBConstants.JOB_TYPE_CONTRACT_KEY; i < DBConstants.JOB_TYPE_OUTSOURCE_KEY; i++){
			codeDesc = new CodeDesc();
			codeDesc.setCode(String.valueOf(i));
			codeDesc.setDesc(getJobTypeDesc(i));
			
			//add the current Object to the list
			jobTypeList.add(codeDesc);
		}//end for
		
		return jobTypeList;
	}//end getAllJobTypes
	
	/**
	 * Method called to get the Job Type Description based on the passed Job Type Key
	 * @param _jobTypeKey
	 * @return
	 */
	public static String getJobTypeDesc(final long _jobTypeKey){
		String _jobTypeDesc = null;
		switch((int)_jobTypeKey){
		case (int)DBConstants.JOB_TYPE_CONTRACT_KEY : _jobTypeDesc = DBConstants.JOB_TYPE_CONTRACT_VALUE;
		break;
		case (int)DBConstants.JOB_TYPE_REGULAR_KEY : _jobTypeDesc = DBConstants.JOB_TYPE_REGULAR_VALUE;
		break;
		case (int)DBConstants.JOB_TYPE_OUTSOURCE_KEY : _jobTypeDesc = DBConstants.JOB_TYPE_OUTSOURCE_VALUE;
		break;
		}
		
		return _jobTypeDesc;
	}//end getJobTypeDesc
	
	
	/**
	 * Customer type
	 * @return
	 */
	public static Object[][] getEmployeeType(){
		Object lookupTypes[][] = {
				{DBConstants.HEADER_DEFAULT_KEY, DBConstants.HEADER_DEFAULT_VALUE},
				{DBConstants.JOB_TYPE_CONTRACT_KEY, DBConstants.JOB_TYPE_CONTRACT_VALUE},
				{DBConstants.JOB_TYPE_REGULAR_KEY, DBConstants.JOB_TYPE_REGULAR_VALUE},
				{DBConstants.JOB_TYPE_OUTSOURCE_KEY, DBConstants.JOB_TYPE_OUTSOURCE_VALUE}
		};
		return lookupTypes;
	}
	
	
	public static Object[][] getAnimalType(){
		Object lookupTypes[][] = {
				{DBConstants.HEADER_DEFAULT_KEY, DBConstants.HEADER_DEFAULT_VALUE},
				{DBConstants.JOB_TYPE_CONTRACT_KEY, DBConstants.JOB_TYPE_CONTRACT_VALUE},
				{DBConstants.JOB_TYPE_REGULAR_KEY, DBConstants.JOB_TYPE_REGULAR_VALUE},
				{DBConstants.JOB_TYPE_OUTSOURCE_KEY, DBConstants.JOB_TYPE_OUTSOURCE_VALUE}
		};
		return lookupTypes;
	}
	
	/**
	 * Customer type
	 * @return
	 */
	public static Object[][] getSex(){
		Object sexType[][] = {
				{DBConstants.PROGENCY_SEX_MALE_KEY, DBConstants.PROGENCY_SEX_MALE_VALUE},
				{DBConstants.PROGENCY_SEX_FEMALE_KEY, DBConstants.PROGENCY_SEX_FEMALE_VALUE},
		};
		return sexType;
	}
	
	/**
	 * Method to get the list of hours
	 * @return hrList
	 */
	public static Object[][] getHours(){
		Object hours[][] = new Object[12][2];
		String _hour = null;
		for(int i=0,hr = 1; hr <= 12; hr++,i++)
		{
			//append 0 for hours less than "10"
			if(hr < 10){
				
				_hour = "0" + hr;
				//hrList.add("0" + hr);
			}else{
				_hour = String.valueOf(hr);
			}
			hours[i][0] = hr;
			hours[i][1] = _hour;
		}//end for

		return hours;
	}
	
	/**
	 * Method to get the list of minutes
	 * @return hrList
	 */
	public static Object[][] getMinutes(){
		Object minutes[][] = new Object[60][2];
		String _minute = null;
		for(int i=0,min = 0; min <= 59; min++,i++)
		{
			//append 0 for hours less than "10"
			if(min < 10){
				
				_minute = "0" + min;
				//hrList.add("0" + hr);
			}else{
				_minute = String.valueOf(min);
			}
			minutes[i][0] = min;
			minutes[i][1] = _minute;
		}//end for

		return minutes;
	}

	
	/**
	 * Method to get the list of hours
	 * @return hrList
	 */
	/*public static List<String> getHours(){
		List<String> hrList = new ArrayList<String>(12);
		for(int hr = 1; hr <= 12; hr++)
		{
			//append 0 for hours less than "10"
			if(hr < 10){
				hrList.add("0" + hr);
			}else
				hrList.add(String.valueOf(hr));
		}//end for

		return hrList;		
	}//end getHours
*/
	/**
	 * Method to get the list of minutes
	 * @return minList
	 */
	/*public static List<String> getMinutes(){
		List<String> minList = new ArrayList<String>(60);
		for(int min = 0; min <= 59; min++)
		{
			//append 0 for minutes less than "10"
			if(min < 10){
				minList.add("0" + min);
			}else
				minList.add(String.valueOf(min));
		}//end for

		return minList;		
	}//end getMinutes
*/

}//end class
